package com.leetcode;

/**
 * 908. 最小差值 I
 * 2022-04-30 每日一题
 *
 * @author fy
 * @date 2022-04-30 23:27
 */
public class Solution908 {

    public int smallestRangeI(int[] nums, int k) {
        int score = Integer.MAX_VALUE;
        for (int i = 0; i < nums.length; i++) {
            for (int j = -k; j <= k; j++) {
                nums[i] += j;
                int sc = range(nums);
                nums[i] -= j;
                if (score > sc) {
                    score = sc;
                }
            }
        }
        return score;
    }

    private int range(int[] nums) {
        int max = -Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;

        for (int num : nums) {
            if (num > max) {
                max = num;
            }
            if (min > num) {
                min = num;
            }
        }
        int score = max - min;
        return score;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{0, 10};
        int k = 2;
        int res = new Solution908().smallestRangeI(nums, k);
        System.out.println(res);
    }

}
